import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../layout/Index'

Vue.use(VueRouter)

const constantRoutes = [
  {
    path: '/login',
    hidden: true,
    component: () => import('@/views/login.vue'),
    meta: { title: '登录' }
  },
  {
    path: '/',
    component: Layout,
    redirect: '/',
    meta: { title: '首页' },
    children: [
      {
        path: '/',
        name: 'Home',
        component: () => import('../views/Home.vue'),
        meta: { title: '首页' }
      },
      {
        path: '/knowledge/detail',
        hidden: true,
        component: () => import('@/views/Knowledge/detail.vue'),
        meta: { title: '知识库详情' }
      },
      {
        path: '/healthRecords/record',
        hidden: true,
        component: () => import('@/views/HealthRecords/records.vue'),
        meta: { title: '个人健康档案' }
      },
      {
        path: '/healthRecords/form',
        hidden: true,
        component: () => import('@/views/HealthRecords/form.vue'),
        meta: { title: '个人健康档案' }
      },
    ]
  },
  {
    path: '/course',
    component: Layout,
    redirect: '/course/list',
    meta: { title: '课程计划' },
    children: [
      {
        path: '/course/list',
        name: 'list',
        component: () => import('../views/Course/list.vue'),
        meta: { title: '课程计划' }
      },
      {
        path: '/course/detail',
        hidden: true,
        component: () => import('@/views/Course/detail.vue'),
        meta: { title: '课程详情' }
      },
      {
        path: '/course/history',
        name: 'courseHistory',
        hidden: true,
        component: () => import('../views/Course/history.vue'),
        meta: { title: '课程历史' }
      },
    ]
  },
  {
    path: '/questionnaire',
    component: Layout,
    redirect: '/questionnaire/list',
    meta: { title: '问卷调查' },
    children: [
      {
        path: '/questionnaire/list',
        name: 'questionnaireList',
        component: () => import('../views/Questionnaire/list.vue'),
        meta: { title: '问卷调查' }
      },
      {
        path: '/questionnaire/detail',
        hidden: true,
        component: () => import('@/views/Questionnaire/detail.vue'),
        meta: { title: '问卷详情' }
      },
      {
        path: '/questionnaire/history',
        name: 'questionnaireHistory',
        hidden: true,
        component: () => import('../views/Questionnaire/history.vue'),
        meta: { title: '调查问卷历史' }
      },
    ]
  }
]
const createRouter = () =>
  new VueRouter({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
